<template>
	<view class="estateGreen">
		<navBar isBack backColor="#000" background="#fff" title="小区绿化" color="#000"></navBar>
		
		<!-- 头部 -->
		<view class="nav" v-if="!scrollStatus">
			<view class="allNum">
				<span>所有图片</span>
				<p>共{{num}}张</p>
			</view>
			<view class="changeBtn" @click="toChange">
				<image v-if="!imgStatus" :src="`${baseImg}/static/onePlusN/seeBig.png`" mode=""></image>
				<image v-else :src="`${baseImg}/static/onePlusN/seeSped.png`" mode=""></image>
				<sapn>{{!imgStatus?'查看大图':'快速浏览'}}</sapn>
			</view>
		</view>
		<view class="activeBtn" @click="toChange" :style="'top:' +navHeight+'px;'" v-else>
			<image v-if="!imgStatus" :src="`${baseImg}/static/onePlusN/seeBig.png`" mode=""></image>
			<image v-else :src="`${baseImg}/static/onePlusN/seeSped.png`" mode=""></image>
			<sapn>{{!imgStatus?'查看大图':'快速浏览'}}</sapn>
		</view>
		<!-- 图片列表 -->
		<view class="imgList" v-if="imgList.length>0">
			<view class="imgItem" :class="{'active':imgStatus}" v-for="(item,index) in imgList" :key="index">
				<image :src="item.path" mode="" @tap='previewImage(imgList,index)'></image>
			</view>
		</view>
		<view class="notList" v-else>
			<image :src="`${baseImg}/static/constr/notList.png`" mode=""></image>
			空空如也
		</view>
	</view>
</template>

<script>
	import service_oneN from '@/service/oneN.js'
	export default{
		data(){
			return{
				baseImg:'http://manager.ryz1620.com',
				imgStatus:false,
				imgList:[],
				scrollStatus:false,
				navHeight:92,
				estate_id:null,
				page:1,
				pagesize:10,
				num:0
			}
		},
		onPageScroll(e) {
			// console.log(e)
			if(e.scrollTop>140){
				this.scrollStatus = true
			}else{
				this.scrollStatus = false
			}
		},
		onLoad(options) {
			this.$utils.getUrl()
			this.estate_id = options.estate_id
			this.navHeight = this.$store.state.system.navBarHeight+10;
			console.log(this.navHeight)
			this.getGreenImg()
		},
		onReachBottom() {
			this.page++;
			uni.showLoading({
				title:'加载中'
			})
			let params = {
				estate_id:this.estate_id,
				page:this.page,
				pagesize:this.pagesize
			}
			service_oneN.getGreenImg(params).then(res=>{
				// console.log(res)
				if(res.code==1){
					this.imgList = this.imgList.concat(res.data)
					this.num = res.data.length
				}
			})
			setTimeout(function(){
				uni.hideLoading()
			},500)
		},
		methods:{
			// 获取绿化图片
			getGreenImg(){
				this.page = 1
				let params = {
					estate_id:this.estate_id,
					page:this.page,
					pagesize:this.pagesize
				}
				service_oneN.getGreenImg(params).then(res=>{
					// console.log(res)
					if(res.code==1){
						this.imgList = res.data?res.data:[];
						this.num = res.data.length
					}
				})
			},
			previewImage(list, index) {
				console.log(list);
				// console.log(index);
				let imgUrl = []
				list.map(item => {
					imgUrl.push(item.path)
				})
				uni.previewImage({
					current: index, //预览图片的下标
					urls: imgUrl //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
				});
			},
			toChange(){
				if(this.imgStatus){
					this.imgStatus = false
				}else{
					this.imgStatus = true
				}
			}
		}
	}
</script>

<style lang="scss">
	page{width: 100%;height: 100%;}
	.estateGreen{
		width: 100%;
		height: 100%;
		background-color: #fff;
		// 头部
		.nav{
			padding: 40rpx 66rpx 60rpx 60rpx;
			display: flex;
			justify-content: space-between;
			font: 400 24rpx/36rpx PingFang SC;
			color: #333;
			align-items: flex-start;
			span{font: 500 32rpx/52rpx PingFang SC;}
			.changeBtn{
				display: flex;
				align-items: center;
				image{width: 28rpx;height: 28rpx;margin-right: 16rpx;}
			}
		}
		.activeBtn{
			position: fixed;
			right: 42rpx;
			display: flex;
			font: 400 24rpx/36rpx PingFang SC;
			justify-content: space-between;
			z-index: 6;
			align-items: center;
			image{width: 28rpx;height: 28rpx;}
			width: 190rpx;
			height: 58rpx;
			border-radius: 32rpx;
			background-color: #fff;
			padding: 0 24rpx;
		}
		
		// 图片列表
		.imgList{
			width: 100%;
			padding: 0 32rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			.imgItem{
				width: 328rpx;
				height: 328rpx;
				border-radius: 16rpx;
				margin-bottom: 32rpx;
				image{width: 100%;height: 100%;border-radius: 16rpx;}
			}
			.active{
				width: 686rpx;
				height: 458rpx;
			}
		}
		
		// 没有图片
		.notList{
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			margin: auto;
			height: 400rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 426rpx;
			image{
				width: 426rpx;
				height: 356rpx;
				margin-bottom: 40rpx;
			}
			font:500 40rpx/56rpx PingFang SC;
			color: #333;
		}
	}
</style>
